import { createSlice } from "@reduxjs/toolkit";
import { setCookie, getCookie } from "@/utils/cookie";

export const Detail = createSlice({
  name: 'detailID',
  initialState: {
    value: (getCookie('ID') || 0) as number,
    fromPath: getCookie('fromPath') || ''
  },
  reducers: {
    saveID: (state, action) =>{
      state.value = action.payload   
      setCookie('ID', action.payload)
    },

    savePath: (state, action) =>{
      state.fromPath = action.payload   
      setCookie('fromPath', action.payload)
    }
  }  
})

export const { saveID, savePath } = Detail.actions
export default Detail.reducer